import React from "react";

import { Divider,Card } from 'antd';

import { ajax, openErrorNotification, openSuccessNotification, showResultMessage, isNotNull, isNull, inArray } from '../../common';

import UIActionBar from '../../uicomponents/UIActionBar';

import UIFormView from '../../uicomponents/UIFormView';

import LessonListTable from './LessonListDataTablePanel.js';

/**
 * 班级课程编辑页面
 */
export default class ClassCourseConfigPanel extends React.Component{

    componentDidMount(){
        this.lessonListRef.loadData();
    }

    actionHandler = (actionEvent,panelInstance) => {
        const classDefine = this.props.location.state.classDefine;
        return {
                                
            refresh : () => {
                panelInstance.loadData();
            },
                                            
            addNew : () => {
                panelInstance.addNew();
            },
                                            
            doDelete : () => {
                panelInstance.doDelete(isNotNull(actionEvent.params) ? actionEvent.params.id : null);
            },
                                                    
            doEdit : () => {
                panelInstance.doEdit(actionEvent.params);
            },						
            doSave : () => {
                panelInstance.doSave({
                    campusId : classDefine.campusId,
                    classId : classDefine.id,
                });
            },
                                                
        };
    }

    onValuesChange = (changedValues, allValues) => {
		// if('repeatPeriod' in changedValues){
        //     console.log(changedValues);
        //     let repeatPeriodValues = changedValues.repeatPeriod;
        //     console.log(inArray('all',repeatPeriodValues));
        //     if(inArray('all',repeatPeriodValues) !== -1 && repeatPeriodValues.length < 8){
        //         this.lessonListRef.dataFormRef.setFieldsValue({
        //             repeatPeriod : ['all','monday','tuesday','wednesday','thursday','friday','saturday','sunday']
        //         });
        //     }

		// 	//this.classDefineListTableRef.dataFormRef.setFormFieldParams('classRoomId',{campusId : changedValues['campusId']});
		// 	//this.setState({formParams : {campusId : changedValues['campusId']}});
		// }
	}

    render(){

        const classDefine = this.props.location.state.classDefine;

        return (
            <React.Fragment>
                <Card title="课程设置" extra={<UIActionBar {...this.props} actionGroupId='goBackActionGroup' actionHandler={() => { }} />} >
                    <LessonListTable 
                        ref={(inst) => { this.lessonListRef = inst }}
                        actionHandler={this.actionHandler} 
                        formParams={{campusId : classDefine.campusId}}
                        onBeforeLoadData={() => {return {classId : classDefine.id}}}
                        initSearchValues={{classId : classDefine.id}}
                        onValuesChange={this.onValuesChange}
                        fieldPropsMap={{
                            startLessonTime : {
                                format : 'HH:mm',
                            },
                            endLessonTime : {
                                format : 'HH:mm',
                            },
                        }}
                    />
                </Card>
                
            </React.Fragment>
        );
    }
}